home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / GEDEV100.ZIP;1 / C.ZIP / GE_DEMO.C next >
Encoding:
C/C++ Source or Header  |  1992-10-12  |  3.2 KB  |  125 lines

  1. /*
  2. **  GEcho 1.00 Developers Kit Demonstration Source Code
  3. **
  4. **  Written by Gerard J. van der Land
  5. **
  6. **  Copyright (C) 1992 Gerard J. van der Land. All rights reserved.
  7. **
  8. **  Last updates: 12-Oct-92
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <io.h>
  13. #include <fcntl.h>
  14.  
  15. typedef unsigned char  byte;
  16. typedef unsigned int   word;
  17. typedef unsigned long  dword;
  18.  
  19. #include "gestruct.h"
  20.  
  21. SETUP_GE sys;
  22. AREAFILE_HDR AreaHdr;
  23. AREAFILE_GE AreaFile;
  24. AREAFILE_GEX AreaIdx[MAXAREAS];
  25. int SetupGE, AreaFileGE, AreaFileGEX;
  26. word result, records, areas, arearecsize, counter;
  27.  
  28. int main(void)
  29. {
  30. /*
  31. **  Opening and reading SETUP.GE
  32. */
  33.    SetupGE = open("SETUP.GE", O_RDONLY|O_DENYWRITE|O_BINARY);
  34.    if (SetupGE == -1)
  35.    {
  36.       printf("Unable to open SETUP.GE\n");
  37.       return(255);
  38.    }
  39.    result = read(SetupGE, &sys, sizeof(SETUP_GE));
  40.    close(SetupGE);
  41.    if (result < sizeof(SETUP_GE))
  42.    {
  43.       printf("Error reading SETUP.GE\n");
  44.       return(255);
  45.    }
  46.    if (sys.sysrev != GE_THISREV)
  47.    {
  48.       printf("System file revision level mismatch\n");
  49.       return(251);
  50.    }
  51.  
  52.    printf("SysOp: %s\n", sys.username[0]);
  53.  
  54. /*
  55. **  Opening AREAFILE.GE and checking the header
  56. */
  57.    AreaFileGE = open("AREAFILE.GE", O_RDWR|O_DENYWRITE|O_BINARY);
  58.    if (AreaFileGE == -1)
  59.    {
  60.       printf("Unable to open AREAFILE.GE\n");
  61.       return(255);
  62.    }
  63.    result = read(AreaFileGE, &AreaHdr, sizeof(AREAFILE_HDR));
  64.    if (result < sizeof(AREAFILE_HDR))
  65.    {
  66.       printf("Error reading AREAFILE header\n");
  67.       return(255);
  68.    }
  69.  
  70.    if (AreaHdr.recsize < sizeof(AREAFILE_GE))
  71.    {
  72.       printf("Incompatible AREAFILE record size\n");
  73.       return(255);
  74.    }
  75.  
  76. /*
  77. **  Reading AREAFILE.GE
  78. **
  79. **  Method 1: Using AREAFILE.GEX index file
  80. **  This will read the area records in alphabetical order, removed area
  81. **  records are automatically skipped.
  82. */
  83.    AreaFileGEX = open("AREAFILE.GEX", O_RDWR|O_DENYWRITE|O_BINARY);
  84.    if (AreaFileGEX == -1)
  85.    {
  86.       printf("Unable to open AREAFILE.GEX\n");
  87.       return(255);
  88.    }
  89.    result = read(AreaFileGEX, &AreaIdx, sizeof(AreaIdx));
  90.    areas = result / sizeof(AREAFILE_GEX);
  91.    close(AreaFileGEX);
  92.  
  93.    for (counter = 0; counter < areas; counter++)
  94.    {
  95.       lseek(AreaFileGE, AreaIdx[counter].offset, SEEK_SET);
  96.       result = read(AreaFileGE, &AreaFile, sizeof(AREAFILE_GE));
  97.       if (result == sizeof(AREAFILE_GE))
  98.       {
  99.          printf("%u %s\n", counter+1, AreaFile.name);
  100.       }
  101.    }
  102.  
  103. /*
  104. **  Reading AREAFILE.GE
  105. **
  106. **  Method 2: Sequentially reading
  107. **  This will read the area records in the order in which they area stored.
  108. **  You will have to check each record to see if it has been removed.
  109. */
  110.    arearecsize = AreaHdr.systems * sizeof(EXPORTENTRY) + AreaHdr.recsize;
  111.    records = (filelength(AreaFileGE) - AreaHdr.hdrsize) / arearecsize;
  112.    areas = 0;
  113.    for (counter = 0; counter < records; counter++)
  114.    {
  115.       lseek(AreaFileGE, (long) AreaHdr.hdrsize + (long) arearecsize * counter, SEEK_SET);
  116.       result = read(AreaFileGE, &AreaFile, sizeof(AREAFILE_GE));
  117.       if (result < sizeof(AREAFILE_GE)) break;
  118.       if ((AreaFile.options & REMOVED) == 0)
  119.          printf("%u %s\n", ++areas, AreaFile.name);
  120.    }
  121.    return(0);
  122. }
  123.  
  124. /* end of file "ge_demo.c" */
  125.